#ifndef tmTimer_h__
#define tmTimer_h__

#include "./tmInclude.h"

typedef VOID    (*TimerProc) (VOID* pUser) ;
class tmTimer : public GLES::Object
{
public:

	typedef struct _myAdapData_
	{
		TimerProc proc;
		VOID*     pUser;
	}myAdapData;

private:
	private:
	//QueryPerformanceFrequency() API can be used or not
	static BOOL m_bUsingQPF;
	//Ticks per second
	static GLES::Uns64 m_llQPFTickesPerSec;


	//time len between GetTicksCounted() and Reset() called excluded m_llUncountedLen
	GLES::Uns64 m_llCountedLen;
	//the sum of time len between Stop() and Start() called
	GLES::Uns64 m_llUncountedLen;
	//time len between GetTimeElapsed() and GetTimeElapsed() called
	GLES::Uns64 m_llElapsedLen;


	//time when GetTimeElapsed called
	GLES::Uns64 m_llLastElapsedTime;	//relative to system time
	//time when Stop() called
	GLES::Uns64 m_llLastStoppedTime;   //relative to system time
	//time when Reset() called
	GLES::Uns64 m_llLastResetedTime;   //relative to system time

public:
	 static GLES::Uns64 GetTicksPerSecond();
	//
	//reset all counters, after Reset, Start should be called to launch the timer
	//*ResetTime: out, the time of time reseted in abslute style
	 VOID Reset(GLES::Uns64* ResetTime = NULL);
	//contuine to count
	//*StartTime: out, the time of timer started in abslute style
	 VOID Start(GLES::Uns64* StartTime = NULL);
	//stop to count but keep counters unchanged
	//*StopTime:out, the time of timer stopped in abslute style
	 VOID Stop(GLES::Uns64* StopTime = NULL);

	//update Timer and return the time from last reset time to now 
	//not including stoped period<---->timecounted
	 GLES::Uns64 CalTicksCounted();
	//update Timer and return the time from last CalTicksElapsed() to now 
	//not including stoped period<---->timecounted
	 GLES::Uns64 CalTicksElapsed();

	//return the time from last CalTicksElapsed() to now 
	//not including stoped period<---->timecounted
	 GLES::Uns64 GetTicksElapsed();
	//return the time from last reset time to now 
	//not including stoped period<---->timecounted
	 GLES::Uns64 GetTicksCounted();
	//Timer stopped
	 BOOL   IsStopped();
public:
	tmTimer();
	~tmTimer();
	BOOL CreateTimer(int timerID,TimerProc proc,int span,VOID* pUser);
	VOID DeleteTimer(int timerID);
private:
	BOOL mCreated;
	UINT mTimerID;
};



#endif // tmTimer_h__